package com.trace.demo.repository;

import com.trace.demo.entity.Farmer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Repository
public interface FarmerRepository extends JpaRepository<Farmer, Long> {
    
    List<Farmer> findByUserId(Long userId);
    
    @Query("SELECT COUNT(f) FROM Farmer f")
    Long countFarmers();
    
    @Query("SELECT COUNT(f) FROM Farmer f WHERE f.createdAt >= ?1")
    Long countTodayNewFarmers(LocalDateTime startOfDay);
    
    @Query("SELECT f.province as province, COUNT(f) as count FROM Farmer f GROUP BY f.province")
    List<Map<String, Object>> countFarmersByProvince();
} 